/**
 * **************************************************************************
 *
 * @说明: 
 * @项目名称: talent-proxy-mysql-common
 *
 * @author: tanyaowu 
 * @创建时间: 2017年1月27日 上午11:43:56
 *
 * **************************************************************************
 */
package com.talent.proxy.mysql.common;

import java.sql.Types;

/**
 * 
 * <pre>
 * 
 * <div class="table-contents"><table class="table" summary="Column Types" border="1">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th scope="col">Table Column Type</th>
<th scope="col">Hex Value</th>
<th scope="col">Notes</th>
</tr></thead>
<tbody>
<tr>
<td scope="row">
<a name="packet-public static final int DECIMAL"></a>public static final int DECIMAL</td>
<td><code class="literal">= 0x00</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::DECIMAL"><code class="literal">ProtocolBinary::DECIMAL</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int TINY"></a>public static final int TINY</td>
<td><code class="literal">= 0x01</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::TINY"><code class="literal">ProtocolBinary::TINY</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int SHORT"></a>public static final int SHORT</td>
<td><code class="literal">= 0x02</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::SHORT"><code class="literal">ProtocolBinary::SHORT</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int LONG"></a>public static final int LONG</td>
<td><code class="literal">= 0x03</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::LONG"><code class="literal">ProtocolBinary::LONG</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int FLOAT"></a>public static final int FLOAT</td>
<td><code class="literal">= 0x04</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::FLOAT"><code class="literal">ProtocolBinary::FLOAT</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int DOUBLE"></a>public static final int DOUBLE</td>
<td><code class="literal">= 0x05</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::DOUBLE"><code class="literal">ProtocolBinary::DOUBLE</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int NULL"></a>public static final int NULL</td>
<td><code class="literal">= 0x06</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::NULL"><code class="literal">ProtocolBinary::NULL</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int TIMESTAMP"></a>public static final int TIMESTAMP</td>
<td><code class="literal">= 0x07</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::TIMESTAMP"><code class="literal">ProtocolBinary::TIMESTAMP</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int LONGLONG"></a>public static final int LONGLONG</td>
<td><code class="literal">= 0x08</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::LONGLONG"><code class="literal">ProtocolBinary::LONGLONG</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int INT24"></a>public static final int INT24</td>
<td><code class="literal">= 0x09</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::INT24"><code class="literal">ProtocolBinary::INT24</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int DATE"></a>public static final int DATE</td>
<td><code class="literal">= 0x0a</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::DATE"><code class="literal">ProtocolBinary::DATE</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int TIME"></a>public static final int TIME</td>
<td><code class="literal">= 0x0b</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::TIME"><code class="literal">ProtocolBinary::TIME</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int DATETIME"></a>public static final int DATETIME</td>
<td><code class="literal">= 0x0c</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::DATETIME"><code class="literal">ProtocolBinary::DATETIME</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int YEAR"></a>public static final int YEAR</td>
<td><code class="literal">= 0x0d</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::YEAR"><code class="literal">ProtocolBinary::YEAR</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int NEWDATE"></a><span class="emphasis"><em>public static final int NEWDATE</em></span>

                      <a href="#ftn.fnref_internal" class="footnote" name="fnref_internal"><sup class="footnote">[a]</sup></a>
</td>
<td><code class="literal">= 0x0e</code></td>
<td>see
                      <a class="link" href="com-query-response.html#packet-public static final int DATE">public static final int DATE</a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int VARCHAR"></a>public static final int VARCHAR</td>
<td><code class="literal">= 0x0f</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::VARCHAR"><code class="literal">ProtocolBinary::VARCHAR</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int BIT"></a>public static final int BIT</td>
<td><code class="literal">= 0x10</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::BIT"><code class="literal">ProtocolBinary::BIT</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int TIMESTAMP2"></a><span class="emphasis"><em>public static final int TIMESTAMP2</em></span>

                      <a href="com-query-response.html#ftn.fnref_internal" class="footnoteref"><sup class="footnoteref">[a]</sup></a>
</td>
<td><code class="literal">= 0x11</code></td>
<td>see
                      <a class="link" href="com-query-response.html#packet-public static final int TIMESTAMP">public static final int TIMESTAMP</a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int DATETIME2"></a><span class="emphasis"><em>public static final int DATETIME2</em></span>

                      <a href="com-query-response.html#ftn.fnref_internal" class="footnoteref"><sup class="footnoteref">[a]</sup></a>
</td>
<td><code class="literal">= 0x12</code></td>
<td>see
                      <a class="link" href="com-query-response.html#packet-public static final int DATETIME">public static final int DATETIME</a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int TIME2"></a><span class="emphasis"><em>public static final int TIME2</em></span>

                      <a href="com-query-response.html#ftn.fnref_internal" class="footnoteref"><sup class="footnoteref">[a]</sup></a>
</td>
<td><code class="literal">= 0x13</code></td>
<td>see
                      <a class="link" href="com-query-response.html#packet-public static final int TIME">public static final int TIME</a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int NEWDECIMAL"></a>public static final int NEWDECIMAL</td>
<td><code class="literal">= 0xf6</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::NEWDECIMAL"><code class="literal">ProtocolBinary::NEWDECIMAL</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int ENUM"></a>public static final int ENUM</td>
<td><code class="literal">= 0xf7</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::ENUM"><code class="literal">ProtocolBinary::ENUM</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int SET"></a>public static final int SET</td>
<td><code class="literal">= 0xf8</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::SET"><code class="literal">ProtocolBinary::SET</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int TINY_BLOB"></a>public static final int TINY_BLOB</td>
<td><code class="literal">= 0xf9</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::TINY_BLOB"><code class="literal">ProtocolBinary::TINY_BLOB</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int MEDIUM_BLOB"></a>public static final int MEDIUM_BLOB</td>
<td><code class="literal">= 0xfa</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::MEDIUM_BLOB"><code class="literal">ProtocolBinary::MEDIUM_BLOB</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int LONG_BLOB"></a>public static final int LONG_BLOB</td>
<td><code class="literal">= 0xfb</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::LONG_BLOB"><code class="literal">ProtocolBinary::LONG_BLOB</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int BLOB"></a>public static final int BLOB</td>
<td><code class="literal">= 0xfc</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::BLOB"><code class="literal">ProtocolBinary::BLOB</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int VAR_STRING"></a>public static final int VAR_STRING</td>
<td><code class="literal">= 0xfd</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::VAR_STRING"><code class="literal">ProtocolBinary::VAR_STRING</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int STRING"></a>public static final int STRING</td>
<td><code class="literal">= 0xfe</code></td>
<td>;//Implemented by
                      <a class="link" href="binary-protocol-value.html#packet-ProtocolBinary::STRING"><code class="literal">ProtocolBinary::STRING</code></a>
</td>
</tr>
<tr>
<td scope="row">
<a name="packet-public static final int GEOMETRY"></a>public static final int GEOMETRY</td>
<td><code class="literal">= 0xff</code></td>
<td>&nbsp;</td>
</tr>
</tbody>
<tbody class="footnotes"><tr><td colspan="3"><div id="ftn.fnref_internal" class="footnote"><p><a href="#fnref_internal" class="para"><sup class="para">[a] </sup></a>
                          Internal to MySQL Server. Not used in
                          <a class="link" href="prepared-statements.html" title="14.7&nbsp;Prepared Statements"><code class="literal">ProtocolBinary::*</code></a>
                          nor
                          <a class="link" href="text-protocol.html" title="14.6&nbsp;Text Protocol"><code class="literal">ProtocolText::*</code></a>.
                        </p></div></td></tr></tbody>
</table></div>
 * </pre>
 * @see https://dev.mysql.com/doc/internals/en/com-query-response.html#column-type
 */
public class MysqlColumnType
{
	public static final int DECIMAL = 0x00;//	;//Implemented by ProtocolBinary::DECIMAL

	public static final int TINY = 0x01;//Implemented by ProtocolBinary::TINY
	public static final int SHORT = 0x02;//Implemented by ProtocolBinary::SHORT
	public static final int LONG = 0x03;//Implemented by ProtocolBinary::LONG
	public static final int FLOAT = 0x04;//Implemented by ProtocolBinary::FLOAT
	public static final int DOUBLE = 0x05;//Implemented by ProtocolBinary::DOUBLE
	public static final int NULL = 0x06;//Implemented by ProtocolBinary::NULL
	public static final int TIMESTAMP = 0x07;//Implemented by ProtocolBinary::TIMESTAMP
	public static final int LONGLONG = 0x08;//Implemented by ProtocolBinary::LONGLONG
	public static final int INT24 = 0x09;//Implemented by ProtocolBinary::INT24
	public static final int DATE = 0x0a;//Implemented by ProtocolBinary::DATE
	public static final int TIME = 0x0b;//Implemented by ProtocolBinary::TIME
	public static final int DATETIME = 0x0c;//Implemented by ProtocolBinary::DATETIME
	public static final int YEAR = 0x0d;//Implemented by ProtocolBinary::YEAR
	public static final int NEWDATE = 0x0e;//	see public static final int DATE
	public static final int VARCHAR = 0x0f;//Implemented by ProtocolBinary::VARCHAR
	public static final int BIT = 0x10;//Implemented by ProtocolBinary::BIT
	public static final int TIMESTAMP2 = 0x11;//	see public static final int TIMESTAMP
	public static final int DATETIME2 = 0x12;//	see public static final int DATETIME
	public static final int TIME2 = 0x13;//	see public static final int TIME
	public static final int NEWDECIMAL = 0xf6;//Implemented by ProtocolBinary::NEWDECIMAL
	public static final int ENUM = 0xf7;//Implemented by ProtocolBinary::ENUM
	public static final int SET = 0xf8;//Implemented by ProtocolBinary::SET
	public static final int TINY_BLOB = 0xf9;//Implemented by ProtocolBinary::TINY_BLOB
	public static final int MEDIUM_BLOB = 0xfa;//Implemented by ProtocolBinary::MEDIUM_BLOB
	public static final int LONG_BLOB = 0xfb;//Implemented by ProtocolBinary::LONG_BLOB
	public static final int BLOB = 0xfc;//Implemented by ProtocolBinary::BLOB
	public static final int VAR_STRING = 0xfd;//Implemented by ProtocolBinary::VAR_STRING
	public static final int STRING = 0xfe;//Implemented by ProtocolBinary::STRING
	public static final int GEOMETRY = 0xff;

	public static final int JSON = 245;
	public static final int NEW_DECIMAL = 246;

	/**
	 * mysql type to java type
	 * @param mysqlType
	 * @return
	 *
	 * @author: tanyaowu
	 * @创建时间:　2017年1月27日 下午12:11:51
	 *
	 */
	public static int mysql2JavaType(int mysqlType)
	{
		int jdbcType;

		switch (mysqlType)
		{

		case DECIMAL:
			jdbcType = Types.DECIMAL;

			break;

		case TINY:
			jdbcType = Types.TINYINT;

			break;

		case SHORT:
			jdbcType = Types.SMALLINT;

			break;

		case LONG:
			jdbcType = Types.INTEGER;

			break;

		case FLOAT:
			jdbcType = Types.REAL;

			break;

		case DOUBLE:
			jdbcType = Types.DOUBLE;

			break;

		case NULL:
			jdbcType = Types.NULL;

			break;

		case TIMESTAMP:
			jdbcType = Types.TIMESTAMP;

			break;

		case LONGLONG:
			jdbcType = Types.BIGINT;

			break;

		case INT24:
			jdbcType = Types.INTEGER;

			break;

		case DATE:
			jdbcType = Types.DATE;

			break;

		case TIME:
			jdbcType = Types.TIME;

			break;

		case DATETIME:
			jdbcType = Types.TIMESTAMP;

			break;

		case YEAR:
			jdbcType = Types.DATE;

			break;

		case NEWDATE:
			jdbcType = Types.DATE;

			break;

		case ENUM:
			jdbcType = Types.CHAR;

			break;

		case SET:
			jdbcType = Types.CHAR;

			break;

		case TINY_BLOB:
			jdbcType = Types.VARBINARY;

			break;

		case MEDIUM_BLOB:
			jdbcType = Types.LONGVARBINARY;

			break;

		case LONG_BLOB:
			jdbcType = Types.LONGVARBINARY;

			break;

		case BLOB:
			jdbcType = Types.LONGVARBINARY;

			break;

		case VAR_STRING:
		case VARCHAR:
			jdbcType = Types.VARCHAR;

			break;

		case STRING:
			jdbcType = Types.CHAR;

			break;
		case GEOMETRY:
			jdbcType = Types.BINARY;

			break;
		case BIT:
			jdbcType = Types.BIT;

			break;
		case NEW_DECIMAL:
		case JSON:
		default:
			jdbcType = Types.VARCHAR;
		}

		return jdbcType;

	}

	/**
	 * mysql type 转换成mysql type name
	 * @param mysqlType
	 * @return
	 *
	 * @author: tanyaowu
	 * @创建时间:　2017年1月27日 下午12:12:38
	 *
	 */
	public static String mysqlType2Name(int mysqlType)
	{
		switch (mysqlType)
		{
		case DECIMAL:
			return "DECIMAL";

		case TINY:
			return "TINY";

		case SHORT:
			return "SHORT";

		case LONG:
			return "LONG";

		case FLOAT:
			return "FLOAT";

		case DOUBLE:
			return "DOUBLE";

		case NULL:
			return "NULL";

		case TIMESTAMP:
			return "TIMESTAMP";

		case LONGLONG:
			return "LONGLONG";

		case INT24:
			return "INT24";

		case BIT:
			return "BIT";

		case DATE:
			return "DATE";

		case TIME:
			return "TIME";

		case DATETIME:
			return "DATETIME";

		case YEAR:
			return "YEAR";

		case NEWDATE:
			return "NEWDATE";

		case ENUM:
			return "ENUM";

		case SET:
			return "SET";

		case TINY_BLOB:
			return "TINY_BLOB";

		case MEDIUM_BLOB:
			return "MEDIUM_BLOB";

		case LONG_BLOB:
			return "LONG_BLOB";

		case BLOB:
			return "BLOB";

		case VAR_STRING:
			return "VAR_STRING";

		case STRING:
			return "STRING";

		case VARCHAR:
			return "VARCHAR";

		case GEOMETRY:
			return "GEOMETRY";

		case JSON:
			return "JSON";

		default:
			return " Unknown MySQL Type # " + mysqlType;
		}}

	/**
	 * 
	 *
	 * @author: tanyaowu
	 * @创建时间:　2017年1月27日 上午11:43:56
	 * 
	 */
	public MysqlColumnType()
	{
	}

	/**
	 * @param args
	 *
	 * @author: tanyaowu
	 * @创建时间:　2017年1月27日 上午11:43:56
	 * 
	 */
	public static void main(String[] args)
	{
	}

}
